import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

import Layout from '@/layout'


export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/register',
    component: () => import('@/views/login/register'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/home',
    children: [{
      path: 'home',
      name: 'Home',
      component: () => import('@/views/home/index'),
      meta: { title: '主页', icon: 'dashboard' }
    }]
  },

  {
    path: '/employees',
    component: Layout,
    redirect: '/employees/list',
    name: 'Employees',
    meta: { title: '员工模块', icon: 'el-icon-s-help' },
    children: [
      {
        path: 'list',
        name: 'ListEmp',
        component: () => import('@/views/employees/list'),
        meta: { title: '员工列表', icon: 'tree' }
      },
      {
        path: 'adopt',
        name: 'adoptEmp',
        component: () => import('@/views/employees/adopt'),
        meta: { title: '通过人才', icon: 'tree' }
      },
      {
        path: 'saveOrEditEmp',
        name: 'SaveEmp',
        hidden: true,
        component: () => import('@/views/employees/save'),
        meta: { title: '添加更新员工', icon: 'tree' }
      },
      {
        path: 'saveOrEditEmp/:id',
        name: 'EditEmp',
        hidden: true,
        component: () => import('@/views/employees/save'),
        meta: { title: '添加更新员工', icon: 'tree' }
      },
      {
        path: 'empInfo/:id',
        name: 'EmpInfo',
        component: () => import('@/views/employees/info'),
        hidden: true,
        meta: { title: '员工详情', icon: 'table' }
      }
    ]
  },

  {
    path: '/organization',
    component: Layout,
    redirect: '/organization/structure',
    name: 'Organization',
    meta: { title: '组织架构', icon: 'dashboard' },
    children: [
      {
        path: 'structure',
        name: 'Structure',
        component: () => import('@/views/organization/index'),
        meta: { title: '组织架构', icon: 'table' }
      },
      {
        path: 'list',
        name: 'OrgList',
        component: () => import('@/views/organization/list'),
        meta: { title: '组织列表', icon: 'table' }
      }
    ]
  },


  {
    path: '/personnel',
    component: Layout,
    redirect: '/personnel/list',
    name: 'Personnel',
    meta: { title: '人才库', icon: 'form' },
    children: [
      {
        path: 'list',
        name: 'PersonnelList',
        component: () => import('@/views/personnel/list'),
        meta: { title: '人才库列表', icon: 'table' }
      },
      {
        path: 'save',
        name: 'SavePersonnel',
        component: () => import('@/views/personnel/save'),
        meta: { title: '添加人才信息', icon: 'tree' }
      },
      {
        path: 'edit/:id',
        name: 'EditPersonnel',
        hidden: true,
        component: () => import('@/views/personnel/save'),
        meta: { title: '修改人才信息', icon: 'tree' }
      },
      {
        path: 'info/:id',
        name: 'infoPersonnel',
        component: () => import('@/views/personnel/info'),
        hidden: true,
        meta: { title: '人才详情', icon: 'table' }
      },
      {
        path: 'review/:id',
        name: 'reviewPersonnel',
        component: () => import('@/views/personnel/review'),
        hidden: true,
        meta: { title: '人才审核', icon: 'table' }
      }
    ]
  },

  {
    path: '/recruit',
    component: Layout,
    redirect: '/recruit/list',
    name: 'Recruit',
    meta: { title: '招聘管理', icon: 'link' },
    children: [
      {
        path: 'list',
        name: 'RecruitList',
        component: () => import('@/views/recruit/list'),
        meta: { title: '招聘简章', icon: 'table' }
      },
      {
        path: 'file',
        name: 'RecruitFile',
        component: () => import('@/views/recruit/file'),
        meta: { title: '归档简章', icon: 'table' }
      },
      {
        path: 'save',
        name: 'RecruitSave',
        component: () => import('@/views/recruit/save'),
        hidden: true,
        meta: { title: '创建招聘简章', icon: 'table' }
      },
      {
        path: 'edit/:id',
        name: 'RecruitEdit',
        component: () => import('@/views/recruit/save'),
        hidden: true,
        meta: { title: '修改招聘简章', icon: 'table' }
      }
    ]
  },


  {
    path: '/pay',
    component: Layout,
    redirect: '/pay/index',
    name: 'Organization',
    meta: { title: '薪酬管理', icon: 'table' },
    children: [
      // {
      //   path: 'index',
      //   name: 'payIndex',
      //   component: () => import('@/views/pay/index'),
      //   meta: { title: '员工工资', icon: 'table' }
      // },
      {
        path: 'list',
        name: 'payPostList',
        component: () => import('@/views/pay/list'),
        meta: { title: '岗位基本工资', icon: 'table' }
      },
      {
        path: 'saveOrEdit/:id',
        name: 'payPostData',
        component: () => import('@/views/pay/save'),
        meta: { title: '岗位薪资表单', icon: 'table' }
      }
    ]
  },

  {
    path: '/user',
    component: Layout,
    redirect: '/user/index',
    name: 'userInfo',
    meta: {title: '员工信息', icon: 'table'},
    hidden: true,
    children: [
        {
          path: 'index',
          name: 'userInfo',
          component: () => import('@/views/user/index'),
          meta: { title: '员工信息', icon: 'table' },
          hidden: true
        }
      ]
  },

  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher
}

export default router
